From 8f05d7e89c8d757384e2dee4858dd1aa2b2b4e4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 28 Aug 2005 03:06:30 +0000 Subject: [PATCH] do a backtrace on babl_fatal() --- ChangeLog | 13 +++++++++++++ babl/babl-component.c | 3 +-- babl/babl-conversion.c | 3 +-- babl/babl-fish.c | 7 +++---- babl/babl-format.c | 8 +++----- babl/babl-internal.c | 14 ++++++++++++++ babl/babl-internal.h | 44 +++++++++++++++++++++++++----------------- babl/babl-model.c | 3 +-- babl/babl-type.c | 3 +-- 9 files changed, 63 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f1e2a2..bfbd6f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-08-28 Øyvind Kolås + + * babl/babl-internal.[ch]: (babl_die): A function to call from + babl_fatal (...), invokes commands resulting in a backtrace, thus + giving context to where things broke. + * babl/babl-component.c: (babl_component_new): + * babl/babl-conversion.c: (babl_conversion_new): + * babl/babl-fish.c: (babl_conversion_find): + * babl/babl-format.c: (format_new), (babl_format_new): + * babl/babl-model.c: (babl_model_new): + * babl/babl-type.c: (babl_type_new): use babl_fatal() instead of + babl_log () on API mistakes. + 2005-08-28 Øyvind Kolås * babl/babl-pixel-format.c: removed diff --git a/babl/babl-component.c b/babl/babl-component.c index 5a8e63c..e5f758b 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -108,8 +108,7 @@ babl_component_new (const char *name, else { - babl_log ("unhandled argument '%s' for format '%s'", arg, name); - exit (-1); + babl_fatal ("unhandled argument '%s' for format '%s'", arg, name); } } diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index a94da09..76bc79c 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -211,8 +211,7 @@ babl_conversion_new (Babl *source, } else { - babl_log ("unhandled argument '%s'", arg); - exit (-1); + babl_fatal ("unhandled argument '%s'", arg); } arg = va_arg (varg, char *); diff --git a/babl/babl-fish.c b/babl/babl-fish.c index da7933e..e33fd36 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -108,10 +108,9 @@ BablConversion *babl_conversion_find (void *source, if (!data.result) { - babl_log ("args=('%s', '%s'): failed, aborting", - data.source->instance.name, data.destination->instance.name); - exit (-1); - return NULL; + babl_fatal ("args=('%s', '%s'): failed, aborting", + data.source->instance.name, + data.destination->instance.name); } return data.result; } diff --git a/babl/babl-format.c b/babl/babl-format.c index 2a53193..1607a8c 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -61,9 +61,8 @@ format_new (const char *name, if (component[j] == model->component[i]) goto component_found; } - babl_log ("matching source component for %s in model %s not found", - model->component[i]->instance.name, model->instance.name); - exit (-1); + babl_fatal ("matching source component for %s in model %s not found", + model->component[i]->instance.name, model->instance.name); component_found: ; } @@ -210,8 +209,7 @@ babl_format_new (const char *name, else { - babl_log ("unhandled argument '%s' for format '%s'", arg, name); - exit (-1); + babl_fatal ("unhandled argument '%s' for format '%s'", arg, name); } } diff --git a/babl/babl-internal.c b/babl/babl-internal.c index 749d58f..8eba491 100644 --- a/babl/babl-internal.c +++ b/babl/babl-internal.c @@ -54,6 +54,20 @@ babl_class_name (BablClassType klass) */ int babl_hmpf_on_name_lookups = 0; +#include +#include + +void +babl_die (void) +{ + char buf[512]; + + sprintf (buf,"echo bt>/tmp/babl.gdb;" + "gdb -q --batch -x /tmp/babl.gdb --pid=%i 2>/dev/null", getpid()); + system (buf); + exit (-1); +} + void babl_internal_init (void) { diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 81842f2..e8d3152 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -39,6 +39,8 @@ #include "babl-extension.h" /* */ +void babl_die (void); + /**** LOGGER ****/ #include @@ -69,6 +71,13 @@ real_babl_log (const char *file, #define babl_log(args...) real_babl_log(__FILE__, __LINE__, __FUNCTION__, args) +#define babl_fatal(args...) \ + do{ \ + real_babl_log(__FILE__, __LINE__, __FUNCTION__, args);\ + babl_die();} \ + while(0); + + /********************/ #define BABL_CLASS_TYPE_IS_VALID(klass_type) \ @@ -107,24 +116,23 @@ type_name##_id (int id) \ return babl; \ } -#define BABL_DEFINE_LOOKUP_BY_NAME(type_name) \ -Babl * \ -type_name (const char *name) \ -{ \ - Babl *babl; \ - \ - if (babl_hmpf_on_name_lookups) \ - { \ - babl_log ("%s(\"%s\"): hmpf!", __FUNCTION__, name); \ - } \ - babl = db_exist (0, name); \ - \ - if (!babl) \ - { \ - babl_log ("%s(\"%s\"): not found", __FUNCTION__, name); \ - exit (-1); \ - } \ - return babl; \ +#define BABL_DEFINE_LOOKUP_BY_NAME(type_name) \ +Babl * \ +type_name (const char *name) \ +{ \ + Babl *babl; \ + \ + if (babl_hmpf_on_name_lookups) \ + { \ + babl_log ("%s(\"%s\"): hmpf!", __FUNCTION__, name); \ + } \ + babl = db_exist (0, name); \ + \ + if (!babl) \ + { \ + babl_fatal ("%s(\"%s\"): not found", __FUNCTION__, name); \ + } \ + return babl; \ } #ifndef BABL_INIT_HOOK diff --git a/babl/babl-model.c b/babl/babl-model.c index d3f12cf..787f5b6 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -148,8 +148,7 @@ babl_model_new (void *first_argument, else { - babl_log ("unhandled argument '%s' for babl_model '%s'", arg, name); - exit (-1); + babl_fatal ("unhandled argument '%s' for babl_model '%s'", arg, name); } arg = va_arg (varg, char *); diff --git a/babl/babl-type.c b/babl/babl-type.c index 7c8fc0c..fbdb9c3 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -125,8 +125,7 @@ babl_type_new (const char *name, else { - babl_log ("unhandled argument '%s' for format '%s'", arg, name); - exit (-1); + babl_fatal ("unhandled argument '%s' for format '%s'", arg, name); } } -- 2.30.2